﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class Investor : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) 
        {
            this.BindList();
        }

    }
    private void BindList()
    {
        string tenChuDauTu = string.Empty;
        if (!string.IsNullOrEmpty(Session["nameCDT"].ToString()))
        {
            tenChuDauTu = Session["nameCDT"].ToString();
        }

        wdg.DataSource = new BLL.BOInvestor(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()).GetInvestors(tenChuDauTu);
        wdg.DataBind();
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        BLL.BOInvestor boInvestor = new BLL.BOInvestor(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        boInvestor.Investor_name = txtTenChuDauTu.Text;
        boInvestor.Invester_address = txtDiaChi.Text;

        boInvestor.CreateInvestor();
        this.BindList();
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        BLL.BOInvestor boInvestor = new BLL.BOInvestor(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        boInvestor.Investor_id = int.Parse(txtMaChuDauTu.Text);
        boInvestor.Investor_name = txtTenChuDauTu.Text;
        boInvestor.Invester_address = txtDiaChi.Text;

        boInvestor.UpdateInvestor();
        this.BindList();
    }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.open('Close.htm', '_self', null);", true);
    }
}